package com.kymatrix.kycarbon.xsmd.system.server.model.form.module;

import com.kymatrix.kycarbon.xsmd.system.server.model.entity.ModuleEntity;
import com.kymatrix.kycarbon.xsmd.common.util.TreeNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.Data;

/**
 * @author liujie
 * @date 2024-03-02
 */
@ApiModel("列表查询模块请求返回")
@Data
public class ListQueryModuleResp extends TreeNode<ListQueryModuleResp> implements Comparable<ListQueryModuleResp> {


    @ApiModelProperty(value = "菜单或按钮名称")
    private String name;

    @ApiModelProperty(value = "路径")
    private String path;

    @ApiModelProperty(value = "类型 ModuleType")
    private String type;

    @ApiModelProperty(value = "图标")
    private String icon;
    
    @ApiModelProperty("排序")
    private Integer sortNo;

    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    /**
     * 转换
     */
    public static ListQueryModuleResp fromEntity(ModuleEntity entity) {
        ListQueryModuleResp res = new ListQueryModuleResp();
        res.setId(entity.getId());
        res.setName(entity.getName());
        res.setPath(entity.getPath());
        res.setType(entity.getType());
        res.setIcon(entity.getIcon());
        res.setSortNo(entity.getSortNo());
        res.setCreateTime(entity.getCreateTime());
        return res;
    }

    @Override
    public int compareTo(ListQueryModuleResp o) {
        if (getSortNo() < o.getSortNo()) {
            return  -1;
        } else if (getSortNo() > o.getSortNo()) {
            return  1;
        } else {
            if (getCreateTime().isBefore(o.getCreateTime())) {
                return 1;
            } else if (getCreateTime().isAfter(o.getCreateTime())) {
                return -1;
            }
        }
        return 0;
    }
}
